package com.fubt.repeat.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class WebContext {

    private static ThreadLocal<Session> sessionHolder = new ThreadLocal<Session>();

    /**
     * 初始化回话消息
     * 
     * @param httpServletRequest
     * @param httpServletResponse
     */
    public static void init(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {

        Session session = new Session(httpServletRequest, httpServletResponse);
        sessionHolder.set(session);

    };

    /**
     * 销毁回话消息
     */
    public static void destroy() {
        sessionHolder.remove();
    }

    /**
     * 获取回话信息
     * 
     * @return
     */
    public static Session getSession() {
        return sessionHolder.get();
    }

    /**
     * 获取HttpServletRequest
     * 
     * @return
     */
    public static HttpServletRequest getHttpServletRequest() {
        return getSession().getHttpServletRequest();
    }

    /**
     * 获取HttpServletResponse
     * 
     * @return
     */
    public static HttpServletResponse getHttpServletResponse() {
        return getSession().getHttpServletResponse();
    }

}
